<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Hooks
| -------------------------------------------------------------------------
| This file lets you define "hooks" to extend CI without hacking the core
| files.  Please see the user guide for info:
|
|	http://codeigniter.com/user_guide/general/hooks.html
|
*/

/**
 * Drop-down Menu
 *
 * @access	public
 * @param	string
 * @param	array
 * @param	string
 * @param	string
 * @return	string
 */
if (TRUE)
//if ( ! function_exists('form_dropdown'))
{
	function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '', $please_choose = FALSE)
	{
		if ( ! is_array($selected))
		{
			$selected = array($selected);
		}
//pr($options);
		// If no selected state was submitted we will attempt to set it automatically
		if (count($selected) === 0)
		{
			// If the form name appears in the $_POST array we have a winner!
			if (isset($_POST[$name]))
			{
				$selected = array($_POST[$name]);
			}
		}

		if ($extra != '') $extra = ' '.$extra;

		echo $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
		
		if (count($options) == 0 && strpos($extra, 'multiple') === FALSE)
		{
			//$extra .= ' disabled'; 
			$fisrt_option = '<option value="0">'.T_('Select')."</option>\n";
		}
		else
		{
			$fisrt_option = '';
		}
		
		$form  = '<select name="'.$name.'"'.$extra.$multiple.">\n" . $fisrt_option;
		
		if ($please_choose != '')
		{
			$form .= '<option value="0">'.T_('Select')."</option>\n";
		}
	
		if (!empty($options))
		{
			foreach ($options as $key => $val)
			{
				$key = (string) $key;
	
				if (is_array($val))
				{
					$form .= '<optgroup label="'.$key.'">'."\n";
	
					foreach ($val as $optgroup_key => $optgroup_val)
					{
						$sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : '';
	
						$form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>\n";
					}
	
					$form .= '</optgroup>'."\n";
				}
				else
				{
					$sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
	
					$form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>\n";
				}
			}
		}

		$form .= '</select>';

		return $form;
	}
}

/* End of file hooks.php */
/* Location: ./system/application/config/hooks.php */